package com.aweqy.porcelain.controller;

import com.aweqy.porcelain.common.BaseResponse;
import com.aweqy.porcelain.common.ResultUtils;
import com.aweqy.porcelain.entity.KilnType;
import com.aweqy.porcelain.service.KilnTypeService;
import com.aweqy.porcelain.common.DeleteRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 窑炉类型相关接口
 */
@RestController
@RequestMapping("/api/kiln_type")
@CrossOrigin
public class KilnTypeController {
    @Autowired
    private KilnTypeService kilnTypeService;

    /**
     * 获取所有窑炉类型信息
     * @return 所有窑炉类型列表
     */
    @GetMapping("/list")
    public BaseResponse<List<KilnType>> list() {
        return ResultUtils.success(kilnTypeService.list());
    }

    /**
     * 根据ID获取窑炉类型详情
     * @param id 类型ID
     * @return 窑炉类型详细信息
     */
    @GetMapping("/{id}")
    public BaseResponse<KilnType> getById(@PathVariable Integer id) {
        return ResultUtils.success(kilnTypeService.getById(id));
    }

    /**
     * 新增窑炉类型信息
     * @param entity 窑炉类型实体
     * @return 是否新增成功
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> add(@RequestBody KilnType entity) {
        return ResultUtils.success(kilnTypeService.save(entity));
    }

    /**
     * 更新窑炉类型信息
     * @param entity 窑炉类型实体
     * @return 是否更新成功
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> update(@RequestBody KilnType entity) {
        return ResultUtils.success(kilnTypeService.updateById(entity));
    }

    /**
     * 删除窑炉类型信息
     * @param request 删除请求，包含主键ID
     * @return 是否删除成功
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest request) {
        return ResultUtils.success(kilnTypeService.removeById(request.getId()));
    }
} 